package com.fy.common.config;

import com.alibaba.fastjson.JSONObject;

import java.io.*;
import java.util.Properties;

public class ProtConfig {

    //public static final String PROT = "8082";
    //dev
    public static final String PROT = "38082";


    public static String TOKEN = "";
    public static final String MODULE_SERVER = "/fy-im-server";


   /* static {
        try {
            Properties properties = new Properties();
            String classPath = System.getProperty("user.dir");
            BufferedReader bufferedReader = new BufferedReader(new FileReader(classPath + "/common/src/main/resources/token.properties"));
            properties.load(bufferedReader);
            String passKey = properties.getProperty("token");
            TOKEN = passKey;
            bufferedReader.close();
        } catch (Exception e) {
            e.printStackTrace();
        }


    }*/


    public static void updateTokenProperties(String body){

        JSONObject object = JSONObject.parseObject(body);
        String token = object.getJSONObject("data").getString("token");
        String classPath = System.getProperty("user.dir");
        String profilePath = classPath + "/common/src/main/resources/token.properties";
        Properties props = new Properties();
        try {
            props.load(new FileInputStream(profilePath));
            OutputStream fos = new FileOutputStream(profilePath);
            props.setProperty("token", token);
            props.store(fos, "Update value");
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }



}
